﻿using Quartz.Spi;
using Quartz;
using System;
using Microsoft.Extensions.DependencyInjection;

namespace Zocono.WCS.HangfireHost.QuartzCore
{
    public class JobFactory : IJobFactory
    {
        private readonly IServiceProvider _ServiceProvider;

        public JobFactory(IServiceProvider serviceProvider)
        {
            _ServiceProvider = serviceProvider;
        }
/// <inheritdoc/>

        public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler)
        {
            return _ServiceProvider.GetRequiredService(bundle.JobDetail.JobType) as IJob;
        }
/// <inheritdoc/>

        public void ReturnJob(IJob job)
        {
            (job as IDisposable)?.Dispose();
        }
    }
}
